<template>
    <div>
        <div>
            <el-button type="danger" size="large" @click="handleAddDialog" :icon="Plus">新增</el-button>
            <el-button type="danger" size="large" @click="ShowMarketList" :icon="Search">查询</el-button>
        </div>
        <br />
        <el-form :inline="true" :model="marketForm" class="demo-form-inline" style="height: 80%;">
            <el-form-item label="销售日期:">
                <el-date-picker v-model="marketForm.sdate" type="date" style="width: 200px" />~
                <el-date-picker v-model="marketForm.edate" type="date" style="width: 200px" />
            </el-form-item>
            <el-form-item label="客户:">
                <el-select v-model="marketForm.client" clearable>
                    <el-option v-for="item in clientList" :key="item.ID" :label="item.Name" :value="item.Name" />
                </el-select>
            </el-form-item>
            <el-form-item label="单据号:">
                <el-input v-model="marketForm.DocumentNumber">
                </el-input>
            </el-form-item>
            <el-form-item label="部门:">
                <el-select v-model="marketForm.DepartmentId" clearable>
                    <el-option v-for="item in DepartInfo" :key="item.id" :label="item.name" :value="item.name" />
                </el-select>
            </el-form-item>
            <el-form-item label="收货地址:">
                <el-input v-model="marketForm.MarketAddress">
                </el-input>
            </el-form-item>
            <el-form-item label="销售员:">
                <el-select v-model="marketForm.SellPeople" clearable>
                    <el-option v-for="item in StaffList" :key="item.id" :label="item.name" :value="item.name"
                        placeholder="请选择销售员" />
                </el-select>
            </el-form-item>
            <el-form-item label="审核状态:">
                <el-radio-group v-model="marketForm.AuditState" class="ml-4">
                    <el-radio :value="0" size="large">全部</el-radio>
                    <el-radio :value="1" size="large">未审核</el-radio>
                    <el-radio :value="2" size="large">已审核</el-radio>
                </el-radio-group>
            </el-form-item>
        </el-form>
        <div>
            <el-button type="danger" size="large" @click="handleDeleteAll" :icon="Delete">删除</el-button>
            <el-button type="danger" size="large" @click="handleExamine" :icon="Stamp">审核</el-button>
            <el-button type="danger" size="large" @click="handleNewExamine" :icon="Stamp">重新审核</el-button>
        </div>
        <br>
        <div v-if="TagBool">
            <el-tag style="width:1920px;color: black;height: 50px;" type="danger" :iocn="Delete">
                <spna style="font-size: 15px">
                    <Warning style="width: 1em; height: 1em; margin-right: 8px" color="red" />
                    <span style="margin-right: 1800px">已选择 {{ TagCount }} 项</span>
                </spna>
            </el-tag>
        </div>
        <div v-else>
            <el-tag style="width:1920px;color: black;height: 50px;" type="success" :iocn="Delete">
                <spna style="font-size: 15px">
                    <SuccessFilled style="width: 1em; height: 1em; margin-right: 8px" color="green" />
                    <span style="margin-right: 1800px">已选择 {{ TagCount }} 项</span>
                </spna>
            </el-tag>
        </div> <br />
        <!-- 个体销售显示 -->
        <el-table ref="multipleTableRef" :data="MarketList" style="width: 100%"
            @selection-change="handleSelectionChange" border>
            <el-table-column type="selection" width="55" />
            <el-table-column label="序号" width="120" fixed>
                <template v-slot="scope">
                    <div>{{ scope.$index + (page.pageIndex - 1) * page.pageSize + 1 }}</div>
                </template>
            </el-table-column>
            <el-table-column label="销售日期" width="120" prop="MarketDate">
                <template v-slot="scope">
                    <span>{{ scope.row.MarketDate ? scope.row.MarketDate.replace('T', ' ').substring(0, 10) : null
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column label="单据号" width="120" prop="DocumentNumber">
            </el-table-column>
            <el-table-column label="客户" width="120" prop="Client">
            </el-table-column>
            <el-table-column label="只数" width="120" prop="SheepNumber">
            </el-table-column>
            <el-table-column label="总成交价(元)" width="120">
                <template v-slot="scope">
                    <span>{{ scope.row.TotalPrice.toFixed(2) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="审核状态" width="120" prop="AuditState">
                <template v-slot="scope">
                    <span v-if="scope.row.AuditState == 1"><el-tag type="danger">未审核</el-tag></span>
                    <span v-if="scope.row.AuditState == 2"><el-tag type="success">已审核</el-tag></span>
                </template>
            </el-table-column>
            <el-table-column label="部门" width="120" prop="DepartmentId">
            </el-table-column>
            <el-table-column label="收货地址" width="120" prop="MarketAddress">
            </el-table-column>
            <el-table-column label="销售人" width="120" prop="SellPeople">
            </el-table-column>
            <el-table-column label="创建人" width="120" prop="CreateBy">
            </el-table-column>
            <el-table-column label="创建时间" width="120" prop="CreateDate">
                <template v-slot="scope">
                    <span>{{ scope.row.CreateDate ? scope.row.CreateDate.replace('T', ' ').substring(0, 19) : null
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column label="修改人" width="120" prop="UpdateBy">
            </el-table-column>
            <el-table-column label="修改时间" width="120" prop="UpdateDate">
                <template v-slot="scope">
                    <span>{{ scope.row.UpdateDate ? scope.row.UpdateDate.replace('T', ' ').substring(0, 19) : null
                        }}</span>
                </template>
            </el-table-column>
            <el-table-column label="审核人" width="120" prop="ExamineBy">
            </el-table-column>
            <el-table-column label="操作" width="140" fixed="right">
                <template v-slot="scope">
                    <el-button link type="primary" size="size" @click="handleGetInfo(scope.row.MarketId)">编辑</el-button>
                    <el-button link type="primary" size="size" @click="handleDelete(scope.row.MarketId)">删除</el-button>
                </template>
            </el-table-column>
            <el-table-column label="审核时间" width="120" prop="ExamineDate">
                <template v-slot="scope">
                    <span>{{ scope.row.ExamineDate ? scope.row.ExamineDate.replace('T', ' ').substring(0, 19) : null
                        }}</span>
                </template>
            </el-table-column>
        </el-table>
        <table style="text-align: center;">
            <tr>
                <td>
                    <div>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[1, 15, 30, 45]" :background="true"
                            layout="slot,total, sizes, prev, pager, next, jumper" :total="page.totalCount"
                            @size-change="handleSizeChange" @current-change="handleCurrentChange" />
                    </div>
                </td>
            </tr>
        </table>
        <!-- 羊只销售弹出层添加 -->
        <el-dialog v-model="dialogTableVisible" title="羊只采购-新增" style="width: 85%; height: 80%;"
            :before-close="handleClose">
            <div>
                <el-button type="danger" size="large" @click="handleAdd" :icon="SuccessFilled">保存</el-button>
            </div>
            <el-form :inline="true" :model="marketInfo" class="demo-form-inline" style="height: 80%;">
                <el-form-item label="销售日期:">
                    <el-date-picker v-model="marketInfo.MarketDate" type="date" aria-label="选择日期"
                        style="width: 200px" />
                </el-form-item>
                <el-form-item label="客户:">
                    <el-select v-model="marketInfo.Client" clearable>
                        <el-option v-for="item in clientList" :key="item.ID" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="销售员:">
                    <el-select v-model="marketInfo.SellPeople" clearable>
                        <el-option v-for="item in StaffList" :key="item.id" :label="item.name" :value="item.name"
                            placeholder="请选择销售员" />
                    </el-select>
                </el-form-item>
                <el-form-item label="部门:">
                    <el-select v-model="marketInfo.DepartmentId" clearable>
                        <el-option v-for="item in DepartInfo" :key="item.id" :label="item.name" :value="item.name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="仓库:">
                    <el-select v-model="marketInfo.Stash" clearable>
                        <el-option v-for="item in StashInfo" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-form-item>
                <el-form-item label="收货地址:">
                    <el-input v-model="marketInfo.MarketAddress">
                    </el-input>
                </el-form-item>
                <el-form-item label="单据号:">
                    <span>{{ marketInfo.Documentnumber }}</span>
                </el-form-item>
            </el-form>
            <el-table ref="multipleTableRef" :data="rowList" style="width: 100%">
                <el-table-column type="selection" width="55" />
                <el-table-column label="序号" width="120">
                    <template v-slot="scope">
                        <div>{{ scope.$index + 1 }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="耳号" width="120">
                    <el-select v-model="marketInfo.Earbugles" clearable @change="GetMarket">
                        <el-option v-for="item in earList" :key="item.id" :label="item.name" :value="item.name" />
                    </el-select>
                </el-table-column>
                <el-table-column label="成交价(元)" width="120">
                    <el-input v-model="marketInfo.PayPrice"></el-input>
                </el-table-column>
                <el-table-column label="定价(元)" width="120">
                    <el-input v-model="marketInfo.FixPrice"></el-input>
                </el-table-column>
                <el-table-column label="折扣比例" width="120">
                    <span v-if="marketInfo.FixPrice == 0 || marketInfo.PayPrice == 0">
                        <span>0</span>
                    </span>
                    <span v-else>{{ (marketInfo.PayPrice / marketInfo.FixPrice).toFixed(2) * 100 }}%</span>
                </el-table-column>
                <el-table-column label="等级" width="120">
                    <el-select v-model="marketInfo.Level" clearable>
                        <el-option v-for="item in genelistInfo" :key="item.value" :label="item.name"
                            :value="item.value" />
                    </el-select>
                </el-table-column>
                <el-table-column label="品种" width="120">
                    <el-select v-model="marketInfo.Breed" clearable>
                        <el-option v-for="item in breed" :key="item.value" :label="item.name" :value="item.value" />
                    </el-select>
                </el-table-column>
                <el-table-column label="性别" width="120">
                    <div v-if="marketInfo.SheepTypeInfo == '后裔'">
                        <span>
                            <el-radio-group v-model="marketInfo.SheepSex" class="ml-4" style="width: 200px;">
                                <el-radio :value="1" size="large">公</el-radio>
                                <el-radio :value="2" size="large">母</el-radio>
                            </el-radio-group>
                        </span>
                    </div>
                    <div v-else>
                        <span>
                            <el-radio-group v-model="marketInfo.SheepSex" class="ml-4" style="width: 200px;"
                                @change="ChangeSex1()">
                                <el-radio :value="1" size="large">公</el-radio>
                                <el-radio :value="2" size="large">母</el-radio>
                            </el-radio-group>
                        </span>
                    </div>
                </el-table-column>
                <el-table-column label="羊只类型" width="120">
                    <div v-if="marketInfo.SheepTypeInfo == '后裔'">
                        <el-select v-model="marketInfo.SheepTypeInfo" clearable>
                            <el-option v-for="item in sheepTypeList" :key="item.value" :label="item.name"
                                :value="item.value" />
                        </el-select>
                    </div>
                    <div v-else>
                        <el-select v-model="marketInfo.SheepTypeInfo" clearable @change="ChangeSex()">
                            <el-option v-for="item in sheepTypeList" :key="item.value" :label="item.name"
                                :value="item.value" />
                        </el-select>
                    </div>
                </el-table-column>
                <el-table-column label="繁殖状态" width="120">
                    <el-select v-model="marketInfo.Propagate" clearable>
                        <el-option v-for="item in GetReproductiveState" :key="item.value" :label="item.name"
                            :value="item.value" />
                    </el-select>
                </el-table-column>
                <el-table-column label="栋舍" prop="CottageName" width="120">
                    <el-select v-model="marketInfo.CottageName" style="width: 200px;" @change="GetField">
                        <el-option v-for="item in Cottage" :key="item.Id" :label="item.Name" :value="item.Name" />
                    </el-select>
                </el-table-column>
                <el-table-column label="栏位" prop="FieldName" width="120">
                    <span>
                        <el-select v-model="marketInfo.FieldName" style="width: 200px;">
                            <el-option v-for="item in Field" :key="item.Id" :label="item.Name" :value="item.Name" />
                        </el-select>
                    </span>
                </el-table-column>
                <el-table-column label="出生日期" prop="BirthDay" width="120">
                    <el-date-picker v-model="marketInfo.BirthDay" type="date" :size="size" />
                </el-table-column>
                <el-table-column label="出生重(kg)" prop="Birthweight" width="120">
                    <el-input v-model="marketInfo.Birthweight"></el-input>
                </el-table-column>
                <el-table-column label="断奶重(kg)" prop="Weaningweight" width="120">
                    <el-input v-model="marketInfo.Weaningweight"></el-input>
                </el-table-column>
                <el-table-column label="父耳号" prop="FatherEar" width="120">
                    <el-input v-model="marketInfo.FatherEar"></el-input>
                </el-table-column>
                <el-table-column label="母耳号" prop="MomtherEar" width="120">
                    <el-input v-model="marketInfo.MomtherEar"></el-input>
                </el-table-column>
                <el-table-column label="月龄" prop="MonthAge" width="120">
                    <el-input v-model="marketInfo.MonthAge"></el-input>
                </el-table-column>
            </el-table>
        </el-dialog>
    </div>
</template>
<script setup lang="ts">
import http from "@/http";
import { ref, reactive, inject, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import {
    Plus,
    Search,
    Delete,
    DocumentChecked,
    Back,
    Warning,
    SuccessFilled,
    Stamp
} from '@element-plus/icons-vue'

const clientList = ref([]);

//获取客户数据
const GetClientData = () => {
    http.get("OrganizationRead/api/Client/GetCliData").then(res => {
        clientList.value = res.data;
    })
}
//添加表单
const marketInfo = reactive({
    MarketId: 0,
    Client: "",
    SellPeople: "",
    DepartmentId: "",
    Stash: "",
    Earbugles: "",
    MarketDate: "",
    MarketAddress: "",
    Documentnumber: "",
    PayPrice: "",
    FixPrice: "",
    Level: "",
    Breed: "",
    SheepSex: "",
    SheepTypeInfo: "",
    CottageName: "",
    FieldName: "",
    Propagate: "",
    BirthDay: "",
    Birthweight: "",
    Weaningweight: "",
    FatherEar: "",
    MomtherEar: "",
    MonthAge: "",
    CreateBy: "",
    CreateDate: "",
    UpdateBy: "",
    UpdateDate: "",
    ExamineBy: "",
    ExamineDate: "",
    AuditState: 0,
    TotalPrice: 0,
    SheepNumber: 0
});
const page = reactive({
    pageIndex: 1,
    pageSize: 15,
    pageCount: 0,
    totalCount: 0
})
//查询条件
const marketForm = reactive({
    sdate: "",
    edate: "",
    client: "",
    DocumentNumber: "",
    DepartmentId: "",
    MarketAddress: "",
    SellPeople: "",
    AuditState: 0
})
const TagBool = ref(true);
const TagCount = ref(0);
let ids = "";
const MarketListSel = ref<{
    MarketId: any,
    Client: any,
    SellPeople: any,
    DepartmentId: any,
    Stash: any,
    Earbugles: any,
    MarketDate: any,
    MarketAddress: any,
    Documentnumber: any,
    PayPrice: any,
    FixPrice: any,
    Level: any,
    Breed: any,
    SheepSex: any,
    SheepTypeInfo: any,
    CottageName: any,
    FieldName: any,
    Propagate: any,
    BirthDay: any,
    Birthweight: any,
    Weaningweight: any,
    FatherEar: any,
    MomtherEar: any,
    MonthAge: any,
    CreateBy: any,
    CreateDate: any
}[]>([]);
//获取选中的数据
const handleSelectionChange = (val: MarketList | any) => {
    MarketListSel.value = val;
    console.log(MarketListSel.value);
    ids = "";
    val.forEach(item => {
        ids += item.PurId + ",";
    });
    ids = ids.substring(0, ids.length - 1);
    TagCount.value = ids.split(",").length;
    if (ids == "") {
        TagCount.value = 0;
    }
    if (TagCount.value == 0) {
        TagBool.value = true
    }
    else {
        TagBool.value = false
    }
}

const handleGetInfo = (MarketId: number) => {
    addFormInfo();
    dialogTableVisible.value = true;
    http.get("routechen/api/ReadMarket/HandleGetMarket?marketId=" + MarketId).then(res => {
        marketInfo.MarketId = res.data.MarketId;
        marketInfo.Earbugles = res.data.Earbugles;
        marketInfo.MarketDate = res.data.MarketDate;
        marketInfo.Client = res.data.Client;
        marketInfo.Client = res.data.Client;
        marketInfo.SellPeople = res.data.SellPeople;
        marketInfo.DepartmentId = res.data.DepartmentId;
        marketInfo.Stash = res.data.Stash;
        marketInfo.MarketAddress = res.data.MarketAddress;
        marketInfo.Documentnumber = res.data.DocumentNumber;
        marketInfo.FixPrice = res.data.FixPrice;
        marketInfo.PayPrice = res.data.PayPrice;
        marketInfo.CreateBy = res.data.CreateBy;
        marketInfo.CreateDate = res.data.CreateDate;
        marketInfo.UpdateBy = res.data.UpdateBy;
        marketInfo.UpdateDate = res.data.UpdateDate;
        marketInfo.SheepNumber = res.data.SheepNumber;
        marketInfo.AuditState = res.data.AuditState;
        marketInfo.TotalPrice = res.data.TotalPrice;
        GetMarket();
    })
}
//批量删除
const handleDeleteAll = () => {
    ElMessageBox.confirm(
        '确定要删除当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.delete("webroute/api/EntityMarket/HandleDelAllMarket?markId=" + MarketListSel.value.map((item) => item.MarketId).toString()).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "删除成功",
                    duration: 2000
                });
                ShowMarketList();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "删除失败",
                    duration: 2000
                });
                ShowMarketList();
            }
        })
    })
}
//批量审核
const handleExamine = () => {
    ElMessageBox.confirm(
        '确定要审核通过当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.put("webroute/api/EntityMarket/HandleAllExamine?marketId=" + MarketListSel.value.map((item) => item.MarketId).toString()).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "审核通过",
                    duration: 2000
                })
                ShowMarketList();
            }
            else if (res.data == -1) {
                ElMessage({
                    type: "error",
                    message: "当前数据当中已有审核通过的数据",
                    duration: 2000
                })
                ShowMarketList();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "审核失败",
                    duration: 2000
                })
                ShowMarketList();
            }
        })
    })
}
//批量重新审核
const handleNewExamine = () => {
    ElMessageBox.confirm(
        '确定要审核通过当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.put("webroute/api/EntityMarket/HandleAllReversal?marketId=" + MarketListSel.value.map((item) => item.MarketId).toString()).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "重新审核",
                    duration: 2000
                })
                ShowMarketList();
            }
            else if (res.data == -1) {
                ElMessage({
                    type: "error",
                    message: "当前数据当中已有重新审核的数据",
                    duration: 2000
                })
                ShowMarketList();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "重新审核失败",
                    duration: 2000
                })
                ShowMarketList();
            }
        })
    })
}
//单个删除
const handleDelete = (MarketId: number) => {
    ElMessageBox.confirm(
        '确定要删除当前数据吗?',
        '警告',
        {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
        }
    ).then(() => {
        http.delete("webroute/api/EntityMarket/HandleDelMarket?markId=" + MarketId).then(res => {
            if (res.data > 0) {
                ElMessage({
                    type: "success",
                    message: "删除成功",
                    duration: 2000
                });
                ShowMarketList();
            }
            else {
                ElMessage({
                    type: "error",
                    message: "删除失败",
                    duration: 2000
                });
                ShowMarketList();
            }
        })
    })
}
const MarketList = ref([]);

const CountNumber = ref(0);
//显示查询方法
const ShowMarketList = () => {
    http.get("routechen/api/ReadMarket/HandleShowMarket", {
        params: {
            pageIndex: page.pageIndex,
            pageSize: page.pageSize,
            sdate: marketForm.sdate,
            edate: marketForm.edate,
            client: marketForm.client,
            DocumentNumber: marketForm.DocumentNumber,
            DepartmentId: marketForm.DepartmentId,
            MarketAddress: marketForm.MarketAddress,
            SellPeople: marketForm.SellPeople,
            AuditState: marketForm.AuditState,
        }
    }).then(res => {
        MarketList.value = res.data.datas;
        page.pageCount = res.data.pageCount;
        page.totalCount = res.data.totalCount;
    })
}
//每页显示条数
const handleSizeChange = (val: number) => {
    page.pageSize = val;
    ShowMarketList();
}
//当前页索引
const handleCurrentChange = (val: number) => {
    page.pageIndex = val;
    ShowMarketList();
}
//添加集合
const rowList = ref([]);
//新增行集合
const newRow = reactive({
    Earbugles: "",
    MarketDate: "",
    MarketAddress: "",
    Documentnumber: "",
    PayPrice: "",
    FixPrice: "",
    Breed: "",
    SheepSex: "",
    SheepTypeInfo: "",
    CottageName: "",
    FieldName: "",
    Propagate: "",
    BirthDay: "",
    Birthweight: "",
    Weaningweight: "",
    FatherEar: "",
    MomtherEar: "",
    MonthAge: "",
    isShow: true
});
//新增行
const addFormInfo = () => {

    marketInfo.MarketId = 0;
    marketInfo.Client = "";
    marketInfo.SellPeople = "";
    marketInfo.DepartmentId = "";
    marketInfo.Stash = "";
    marketInfo.MarketAddress = "";
    marketInfo.Earbugles = "";
    marketInfo.Level = "";
    marketInfo.MarketDate = "";
    marketInfo.MarketAddress = "";
    marketInfo.Documentnumber = "";
    marketInfo.PayPrice = "";
    marketInfo.FixPrice = "";
    marketInfo.Breed = "";
    marketInfo.SheepSex = "";
    marketInfo.SheepTypeInfo = "";
    marketInfo.CottageName = "";
    marketInfo.FieldName = "";
    marketInfo.Propagate = "";
    marketInfo.BirthDay = "";
    marketInfo.Birthweight = "";
    marketInfo.Weaningweight = "";
    marketInfo.FatherEar = "";
    marketInfo.MomtherEar = "";
    marketInfo.MonthAge = "";
    rowList.value.push(newRow);
}
//弹出层绑定
const dialogTableVisible = ref(false);
// 生成一个10位数的随机数
const getRandomNumber = () => {
    const min = Math.pow(10, 9); // 最小边界，10的9次方
    const max = Math.pow(10, 10) - 1; // 最大边界，10的10次方减一
    return Math.floor(Math.random() * (max - min + 1) + min);
};
//新增
const handleAddDialog = () => {
    addFormInfo();
    marketInfo.Documentnumber = getRandomNumber();
    marketInfo.MarketId = 0;
    dialogTableVisible.value = true;
}
const handleClose = () => {
    rowList.value = [];//清空新增行
    dialogTableVisible.value = false;
}
//保存方法
const handleAdd = () => {
    if (marketInfo.MarketId == 0) {
        if (marketInfo.Earbugles != "") {
            http.get("MYroute/api/SheepFile/SheepFileConditionFinds?card=" + marketInfo.Earbugles).then(res => {
                var form = res.data;
                if (form.presence = 3) {
                    ElMessage({
                        message: "该羊只已销售",
                        type: "success",
                        duration: 2000
                    })
                }
            });
        }
        http.post("webroute/api/EntityMarket/HandleAddMarket", marketInfo).then(res => {
            if (res.data > 0) {
                //更改档案的在场状态为销售离场
                http.get("MYroute/api/SheepFile/SheepFileConditionFinds?card=" + marketInfo.Earbugles).then(res => {
                    var form = res.data;
                    form.presence = 3;
                    http.put("Mroute/api/SheepFile/SheepFileConditionUpdate", form)
                    console.log(form);
                });
                ElMessage({
                    message: '保存成功',
                    type: 'success',
                    duration: 2000
                })
                handleClose();
                ShowMarketList();
            } else {
                ElMessage({
                    message: '保存失败',
                    type: 'error',
                    duration: 2000
                })
            }
        })
    } else {
        http.put("webroute/api/EntityMarket/HandleUpdMarket", marketInfo).then(res => {
            if (res.data > 0) {
                ElMessage({
                    message: '修改成功',
                    type: 'success',
                    duration: 2000
                })
                handleClose();
                ShowMarketList();
            } else {
                ElMessage({
                    message: '修改失败',
                    type: 'error',
                    duration: 2000
                })
            }
        })
    }

}
//采购员集合
const StaffList = ref([]);
//采购员下拉方法
const GetStaff = () => {
    http.get("Readroute/api/StaffInfo/GetStaff").then(res => {
        StaffList.value = res.data;
    })
}
//耳号集合
const earList = ref([]);
//耳号下拉方法
http.get("MYroute/api/SheepFile/SheepFileConditionEard").then(res => {
    earList.value = res.data;
})
//仓库集合
const StashInfo = ref([]);
//仓库类型
const GetStashInfo = () => {
    http.get("/routechen/api/ReadPurchase/HandleStash").then(res => {
        StashInfo.value = res.data;
    });
}
//部门集合
const DepartInfo = ref([]);
//部门方法
const GetDaparment = () => {
    http.get("Readroute/api/Department/GetDepartmentInfo").then(res => {
        DepartInfo.value = res.data;
    })
}
//基因
const genelistInfo = ref([]);
//基因下拉方法
const genelist = () => {
    http.get("MYroute/api/SheepFile/GetGeneClass").then(res => {
        genelistInfo.value = res.data;
    })
}
//品种
const breed = ref([]);
//品种下拉
const breedlist = () => {
    http.get("MYroute/api/LamBing/GetBreed").then(res => {
        breed.value = res.data;
    })
}

//羊只类型
const sheepTypeList = ref([]);
//羊只类型下拉方法
const GetSheepTypeInfo = () => {
    http.get("MYroute/api/SheepFile/GetGrowthSheepType").then(res => {
        sheepTypeList.value = res.data;

    })
}
//栋舍集合
const Cottage = ref([]);
//栋舍下拉方法
const GetCooter = () => {
    http.get("OrganizationRead/api/Cottage/HandleGetCot").then(res => {
        Cottage.value = res.data;
    })
}
//栏位集合
const Field = ref([]);
//栏位下拉方法
const GetField = () => {
    http.get("OrganizationRead/api/Field/HandleGetSheepFarm?Id=" + marketInfo.CottageName).then(res => {
        Field.value = res.data;
    })
}
//繁殖状态
const GetReproductiveState = ref()
const GetReproductiveStatelist = () => {
    http.get("MYroute/api/SheepFile/GetReproductiveState").then(res => {
        GetReproductiveState.value = res.data;
    })
}
//获取羊只档案数据
const GetMarket = () => {
    http.get("MYroute/api/SheepFile/SheepFileConditionFinds?card=" + marketInfo.Earbugles).then(res => {
        genelist();
        marketInfo.Level = res.data.geneClass;
        breedlist();
        marketInfo.Breed = res.data.breed;
        GetSheepTypeInfo();
        marketInfo.SheepTypeInfo = res.data.sheepType;
        marketInfo.SheepSex = res.data.sex;
        GetReproductiveStatelist();
        marketInfo.Propagate = res.data.reproductiveState;
        GetCooter();
        marketInfo.CottageName = res.data.cottage;
        GetField();
        marketInfo.FieldName = res.data.field;
        marketInfo.BirthDay = res.data.birthday;
        marketInfo.Birthweight = res.data.birthWeight;
        marketInfo.Weaningweight = res.data.weaningWeight;
        marketInfo.FatherEar = res.data.fatherHorn;
        marketInfo.MomtherEar = res.data.femaleHorn;
        marketInfo.MonthAge = res.data.ageMoon;
        GetStashInfo();
        GetDaparment();
        GetStaff();
        console.log(res.data);
    })
}
//性别转换
const ChangeSex = () => {
    if (marketInfo.SheepTypeInfo == "后裔") {
        marketInfo.SheepSex = "";

    }
    else {
        if (marketInfo.SheepTypeInfo == "种公") {
            marketInfo.SheepSex = "1";
        }
        else if (marketInfo.SheepTypeInfo == "种母") {
            marketInfo.SheepSex = "2";
        }
        else {
            marketInfo.SheepSex = "";
        }
    }
}
const ChangeSex1 = () => {
    if (marketInfo.SheepSex == "1") {
        marketInfo.SheepTypeInfo = "种公";
    }
    else if (marketInfo.SheepSex == "2") {
        marketInfo.SheepTypeInfo = "种母";
    }
    else {
        marketInfo.SheepSex = "";
    }
}
onMounted(() => {
    GetStaff();
    GetStashInfo();
    GetDaparment();
    genelist();
    breedlist();
    GetSheepTypeInfo();
    GetCooter();
    GetReproductiveStatelist();
    GetClientData();
    ShowMarketList();
})

</script>